package com.gu.controller;

import com.gu.entity.EduVideo;
import com.gu.entity.vo.VideoVo;
import com.gu.service.EduVideoService;
import entity.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Description:
 *
 * @Autor: Rolin
 * datetime: 05-21-15:47
 */
@Api(tags = "章节小节管理")
@RequestMapping("/eduService/video")
@RestController
@CrossOrigin
public class EduVideoController {

    @Resource
    private EduVideoService eduVideoService;

    @ApiOperation("根据videoId查询小节")
    @GetMapping("/getVideoById/{id}")
    public CommonResult getVideoById(@PathVariable("id")String videoId){
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return !StringUtils.isEmpty(eduVideo.getTitle()) ? CommonResult.success().data("video",eduVideo) : CommonResult.error();

    }

    @ApiOperation("删除小节")
    @DeleteMapping("/deleteVideo/{id}")
    public CommonResult deleteById(@PathVariable("id") String videoId) {
        boolean result = eduVideoService.deleteByVideoId(videoId);
        return result ? CommonResult.success().data("result", true) : CommonResult.error().data("result", false);
    }

    @ApiOperation("新增小节")
    @PostMapping("/addVideo")
        public CommonResult addVideo(@RequestBody VideoVo videoVo){
        System.out.println(videoVo);
        boolean result = eduVideoService.save(videoVo);
        return result? CommonResult.success().data("result",true):CommonResult.error().data("result",false);
    }

    @ApiOperation("更新小节")
    @PutMapping("/updateById")
    public CommonResult updateVideoById (@RequestBody VideoVo videoVo){
        boolean result = eduVideoService.updateById(videoVo);
        return result? CommonResult.success().data("result",true):CommonResult.error().data("result",false);
    }
}
